package com.watering.plan;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class ShowPlant extends Activity {
	
	Toast ts;
	String value;
	
	public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	value = new String();
    	Bundle extras = getIntent().getExtras(); 
    	if(extras !=null)
    		 value = extras.getString("plantname");

    	String info= new String();
	    Base bs = new Base(this);
	    try{
				bs.createDataBase();
				bs.openDataBase();
				info = bs.getPlantReg(value);
				bs.close();
		}catch(Exception e){
			info = "Could not find plant";
		}

        ts =  Toast.makeText(this, R.string.show_profile_help, Toast.LENGTH_LONG);
        
		
    	setContentView(R.layout.showplant);
    	
        ImageView img = (ImageView)findViewById(R.id.helpbutton);
        img.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	       	ts.show();
	         }
	     });
    	
   	 	TextView t = new TextView(this); 
   	 	t=(TextView)findViewById(R.id.texting);
   	 	t.setText(value);
   	 	
   	 	TextView t2 = new TextView(this); 
	 	t2=(TextView)findViewById(R.id.result);
	 	t2.setText(info);
	 	
	 	t2.setMovementMethod(ScrollingMovementMethod.getInstance());

	     Button NewPlantButton = (Button) findViewById(R.id.change);
	     NewPlantButton.setOnClickListener(new OnClickListener() {
	         public void onClick(View v) {
	        	 Intent myIntent = new Intent(ShowPlant.this, ChangePlant.class);
	        	 myIntent.putExtra("plantname", value );	 	
		     	 startActivity(myIntent);

	         }
	     });
   	 	
   	 	
	}  
}